<!DOCTYPE html>
<html lang="zh">
<head>
	#@header()
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse" >
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								用户名：<input type="text" name="username"/>
							</li>


							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增
	            </a>

	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>


	#@footer()
	<script type="text/javascript">
		var editFlag = true;
		var removeFlag = true;
		$(function() {
		    var options = {
		        url: "#(prj)/super-admin/account/paginate",
		        createUrl: "#(prj)/super-admin/account/add",
		        updateUrl: "#(prj)/super-admin/account/edit/{id}",
		        removeUrl: "#(prj)/super-admin/account/delete/{id}",
		        exportUrl: "#(prj)/super-admin/account/export",
		        sortName: "create_time",
		        modalName: "管理员",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                onEditableSave: onEditableSave,
                showPageGo: true,
		        columns: [
				{
					field: 'id',
					title: 'ID',
					sortable: true
				},
		        {
		            field: 'username',
		            title: '用户名',
					editable : true,

		        },
		        {
		            field: 'password',
		            title: '密码',
		            sortable: true,
		        },
				{
					field: 'salt',
					title: '加密盐',
                    editable: true,
				},
				{
					field: 'sort',
					title: '排序',
				},
				{
					field: 'error_time',
					title: '错误次数',
				},
		        {
		            field: 'create_time',
		            title: '创建时间',
		            sortable: true
		        },
				{
					field: 'update_time',
					title: '更新时间',
					sortable: true
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                    var actions = []
		                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ')
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ')
		                    return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

        function onEditableSave (field, row, rowIndex, oldValue, $el) {
			var formData = new FormData();
            formData.append('account.id',row.id);
            formData.append('account.'+field,row[field])

            $.ajax({
                url:"#(prj)/super-admin/account/update",
                type: "post",
                data: formData,
                contentType: false,
                processData: false,
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                },
                success: function (result) {
                    $.operate.ajaxSuccess(result);
                }
            });

        }
		/* 后台管理状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}

		/* 后台管理-停用 */
		function disable(id) {
			$.modal.confirm("确认<span style='color: red'>锁定</span>该用户吗？", function() {
			    $.post("#(prj)/super-admin/account/onLock",{"id":id},function (res) {
					if(res.state == 'ok'){
					    $.modal.msgSuccess(res.msg)
                        $.table.refresh();
					}
                })
		    })
		}

		/* 后台管理启用 */
		function enable(id) {
			$.modal.confirm("确认<span style='color: green'>解锁</span>该用户吗？", function() {
                $.post("#(prj)/super-admin/account/offLock",{"id":id},function (res) {
                    if(res.state == 'ok'){
                        $.modal.msgSuccess(res.msg)
                        $.table.refresh();
                    }
                })
		    })
		}
	</script>
</body>
</html>